package com.fsck.k9.accounts;

import java.util.StringTokenizer;

/*
 * Used to save K-9 Mail accounts descriptors in widget preferences
 * & also to be displayed in the spinner box to select a K-9 Mail account 
 */
public class Account {

	private String name;
	private String uuId;
	private Integer id;

	public String getAccountName() {
		return this.name;
	}
	
	public Integer getId()
	{
		return this.id;
	}

	public String toString(boolean allData) {
		return this.name
				+ (allData == true ? "\n" + this.uuId + "\n" + this.id : "");
	}

	public String toString() {
		return this.toString(false);
	}

	public String getUuid() {
		return this.uuId;
	}

	Account(String accountName, String accountUuid, Integer id) {
		this.name = accountName;
		this.uuId = accountUuid;
		this.id = id;
	}

	static public Account valueOf(String str) {
		if (str == null)
			return null;

		StringTokenizer toRead = new StringTokenizer(str, "\n");

		String accountName = null;
		Integer accountId = null;
		String accountUuid = null;
		if (toRead.hasMoreTokens()) {
			accountName = toRead.nextToken();
			if (toRead.hasMoreTokens()) {
				accountUuid = toRead.nextToken();
				if (toRead.hasMoreTokens())
					accountId = Integer.valueOf(toRead.nextToken());

			}

		}

		return new Account(accountName, accountUuid, accountId);
	}
}
